package com.ruoyi.hospital.service.impl;

import java.util.List;

import com.ruoyi.hospital.domain.HosBunk;
import com.ruoyi.hospital.service.IHosBunkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hospital.mapper.HosWardMapper;
import com.ruoyi.hospital.domain.HosWard;
import com.ruoyi.hospital.service.IHosWardService;

/**
 * 病房信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@Service
public class HosWardServiceImpl implements IHosWardService 
{
    @Autowired
    private HosWardMapper hosWardMapper;

    @Autowired
    private IHosBunkService hosBunkService;

    /**
     * 查询病房信息
     * 
     * @param wardId 病房信息主键
     * @return 病房信息
     */
    @Override
    public HosWard selectHosWardByWardId(Long wardId)
    {
        return hosWardMapper.selectHosWardByWardId(wardId);
    }

    /**
     * 查询病房信息列表
     * 
     * @param hosWard 病房信息
     * @return 病房信息
     */
    @Override
    public List<HosWard> selectHosWardList(HosWard hosWard)
    {
        // 动态查询病房拥有的床位数量
        List<HosWard> wardList = hosWardMapper.selectHosWardList(hosWard);
        if (wardList.isEmpty()) return wardList;
        for (HosWard ward : wardList) {
            Long wardId = ward.getWardId();
            HosBunk hosBunk = new HosBunk();
            hosBunk.setWardId(wardId);
            List<HosBunk> bunkList = hosBunkService.selectHosBunkList(hosBunk);
            if (bunkList.isEmpty()) ward.setBunkSum(0);
            else ward.setBunkSum(bunkList.size());
        }
        return wardList;
    }

    /**
     * 新增病房信息
     * 
     * @param hosWard 病房信息
     * @return 结果
     */
    @Override
    public int insertHosWard(HosWard hosWard)
    {
        hosWard.setWardId(System.currentTimeMillis());
        return hosWardMapper.insertHosWard(hosWard);
    }

    /**
     * 修改病房信息
     * 
     * @param hosWard 病房信息
     * @return 结果
     */
    @Override
    public int updateHosWard(HosWard hosWard)
    {
        return hosWardMapper.updateHosWard(hosWard);
    }

    /**
     * 批量删除病房信息
     * 
     * @param wardIds 需要删除的病房信息主键
     * @return 结果
     */
    @Override
    public int deleteHosWardByWardIds(Long[] wardIds)
    {
        return hosWardMapper.deleteHosWardByWardIds(wardIds);
    }

    /**
     * 删除病房信息信息
     * 
     * @param wardId 病房信息主键
     * @return 结果
     */
    @Override
    public int deleteHosWardByWardId(Long wardId)
    {
        return hosWardMapper.deleteHosWardByWardId(wardId);
    }
}
